package com.suxin.plugin.intergration.factory.process;

import com.suxin.plugin.intergration.factory.PluginRegistryInfo;
import com.suxin.plugin.intergration.factory.SpringBeanRegister;
import com.suxin.plugin.intergration.factory.process.post.PluginConfigurePostProcessor;
import com.suxin.plugin.intergration.factory.process.post.PluginControllerPostProcessor;
import com.suxin.plugin.intergration.factory.process.post.PluginPostProcessor;
import org.springframework.context.ApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Tang
 * @classname PluginPostProcessorFactory
 * @description [  ]
 * @date 2022/7/23 14:19
 */
public class PluginPostProcessorFactory implements PluginPostProcessor {

    private final List<PluginPostProcessor> pluginPostProcessorList = new ArrayList<>(10);

    private final ApplicationContext applicationContext;

    public PluginPostProcessorFactory(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;

    }

    @Override
    public void initialize() throws Exception {
        pluginPostProcessorList.add(new PluginConfigurePostProcessor(applicationContext));
        pluginPostProcessorList.add(new PluginControllerPostProcessor(applicationContext));

        for (PluginPostProcessor pluginPostProcessor : pluginPostProcessorList) {
            pluginPostProcessor.initialize();
        }

    }

    @Override
    public void registry(List<PluginRegistryInfo> pluginRegistryInfos) throws Exception {
        for (PluginPostProcessor pluginPostProcessor : pluginPostProcessorList) {
            pluginPostProcessor.registry(pluginRegistryInfos);
        }
    }

    @Override
    public void unRegistry(List<PluginRegistryInfo> pluginRegistryInfos) {

    }
}